package com.onlinetask.auth.service;

import com.onlinetask.common.IService;
import com.onlinetask.common.exception.AppException;
import com.onlinetask.common.exception.SysException;
import com.onlinetask.mapper.auth.AuthentificationMapper;
import org.apache.log4j.Logger;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: liyuanliu
 * Date: 13-11-18
 * Time: 下午1:23
 * To change this template use File | Settings | File Templates.
 */
@Service
public class AuthenticationService{
    private static Logger logger = Logger.getLogger(AuthenticationService.class);

    private SqlSessionTemplate sqlSession;

    @Resource(name="authentificationMapper")
    private AuthentificationMapper authentificationMapper;

    public void setSqlSession(SqlSessionTemplate sqlSession) {
        this.sqlSession = sqlSession;
    }

    public void setAuthentificationMapper(AuthentificationMapper authentificationMapper) {
        this.authentificationMapper = authentificationMapper;
    }

    public Map<String,String> authLogin(String userName, String password) throws AppException, SysException {
        Map<String, String> resultMap = new HashMap<String, String>();
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("userName",userName);
        parameterMap.put("userPassword",password);
        int result = authentificationMapper.getUserExists(parameterMap);
        if(result == 0){
            resultMap.put("code","1");
            resultMap.put("message","查询无此用户");
        }else{
            resultMap.put("code","0");
            resultMap.put("message","用户验证成功");
        }
        return resultMap;
    }
}
